var defalutAwardsDateType = 1;
var onloading = false;
/***
 * 切换TAB
 * @param this_
 */
function tabFuc(this_){

    // 避免重复请求
    if (onloading) return;
    onloading = true;

    // 切换css
    $(".tab").removeClass('bd');
    $(this_).addClass('bd');

    // 加载列表
    $("#voteAwardsNameList").empty();
    defalutAwardsDateType = $(this_).attr("date_type_val");
    $.ajaxSettings.async = true;
    $.get("/portals/vote/jsp/mobile/awardsData.jsp?dateType="+defalutAwardsDateType, function(resp){
        var html='';
        if (resp.code == 200) {
            resp.data.forEach(function(json){
                html +='<div class="list"  onclick="selectedVoteAwardsFunc(this)"  date_type_val="'+json.dateType+'" awards_id="'+json.id+'" >';
                html +='    <div class="df">';
                html +='        <div class="list-title">'+json.name+'</div>';
                switch (json.status) {
                    case 0:
                        html +='        <div class="list-status">进行中</div>';
                        break;
                    case 1:
                        html +='        <div class="list-status-green">进行中</div>';
                        break;
                    default:
                        html +='        <div class="list-status-gray">进行中</div>';
                        break;
                }
                html +='    </div>';
                html +='    <div class="df list-detail">';
                html +='        <div><img src="../img/mobile/page.png" alt=""></div>';
                html +='        <div class="ml1">奖项详情：</div>';
                if (json.hasAbout){
                    html +='        <div class="c5f9dab">查看详情</div>';
                } else {
                    html +='        <div class="c9e9e9e">暂无</div>';
                }
                html +='        <div class="ml1"><img src="../img/mobile/r.png" alt=""></div>';
                html +='    </div>';
                html +='</div>';
            });
        }else {
            console.log(resp.msg);
        }
        $("#voteAwardsNameList").append(html);
    });
    onloading = false;
};

/***
 * 新窗口打开
 * @param this_
 */
function selectedVoteAwardsFunc(this_){
    window.open("detail.jsp?id="+$(this_).attr("awards_id"));
}

$(function() {
    // 避免重复请求
    if (onloading) return;
    onloading = true;
    // 数据默认加载年度奖项
    $.ajaxSettings.async = false;
    // 加载列表
    $("#voteAwardsNameList").empty();
    $.ajaxSettings.async = true;
    $.get("/portals/vote/jsp/mobile/awardsData.jsp?dateType="+defalutAwardsDateType, function(resp){
        var html='';
        if (resp.code == 200) {
            resp.data.forEach(function(json){
                html +='<div class="list"  onclick="selectedVoteAwardsFunc(this)"  date_type_val="'+json.dateType+'" awards_id="'+json.id+'" >';
                html +='    <div class="df">';
                html +='        <div class="list-title">'+json.name+'</div>';
                switch (json.status) {
                    case 0:
                        html +='        <div class="list-status">进行中</div>';
                        break;
                    case 1:
                        html +='        <div class="list-status-green">进行中</div>';
                        break;
                    default:
                        html +='        <div class="list-status-gray">进行中</div>';
                        break;
                }
                html +='    </div>';
                html +='    <div class="df list-detail">';
                html +='        <div><img src="../img/mobile/page.png" alt=""></div>';
                html +='        <div class="ml1">奖项详情：</div>';
                if (json.hasAbout){
                    html +='        <div class="c5f9dab">查看详情</div>';
                } else {
                    html +='        <div class="c9e9e9e">暂无</div>';
                }
                html +='        <div class="ml1"><img src="../img/mobile/r.png" alt=""></div>';
                html +='    </div>';
                html +='</div>';
            });
        }else {
            console.log(resp.msg);
        }
        $("#voteAwardsNameList").append(html);
    });
    onloading = false;
});